package main

import (
	"github.com/kardianos/service"
	"log"
	"os"
	"path/filepath"
	"virus-proxy/cmd/my_service"
)

func main_service() {
	//my_service.OutputDebugString("Main starting...")
	ex, err := os.Executable()
	if err != nil {
		//OutputDebugString("Error find current directory " + err.Error())
		log.Fatalf("Error find current directory %v", err)
	}
	exPath := filepath.Dir(ex)
	// 服务的名称、显示名称和描述
	svcConfig := &service.Config{
		Name:             "AVAgent",
		DisplayName:      "Anti Virus Agent Service",
		Description:      "Anti Virus Agent,Support HuoRong Security,QiAnXin Security",
		WorkingDirectory: exPath,
	}

	prg := &my_service.MyService{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}

	// 如果服务已经安装，可以通过以下命令来启动、停止、重启或卸载服务：
	// service.exe install
	// service.exe start
	// service.exe stop
	// service.exe restart
	// service.exe uninstall

	// 通过以下代码来控制服务的启动和停止
	if len(os.Args) > 1 {
		err = service.Control(s, os.Args[1])
		if err != nil {
			log.Fatal(err)
		}
		return
	}

	err = s.Run()
	if err != nil {
		log.Fatal(err)
	}
}
